package com.ltv.xiangqiplugin.models;

import java.util.Vector;

public class Shi extends Piece {
	private static Shi shi;

	private Shi() {
	}

	public static Vector<Destination> possibleDestinations(char board[][], SquareCoord origin, boolean checkCheck) {
		if (shi == null) {
			shi = new Shi();
		}

		return shi._possibleDestinations(board,origin, checkCheck);
	}

	private Vector<Destination> _possibleDestinations(char board[][], SquareCoord origin, boolean checkCheck) {
		Vector<Destination> moves = new Vector<Destination>();
		int x = origin.getRow();
		int y = origin.getFile();
		char [][] tempBoard = fillTempBoard(board);
		tempBoard[x][y] = ' ';
		char piece = board[x][y];
		char color = ' ';
		if (Character.isUpperCase(piece)) color = 'r';
		else color = 'b';

		if (y > 3) {
			if ((color == 'r' && x > 0) || (color == 'b' && x > 7)) {
				checkMove(moves, x-1, y-1, piece, color, tempBoard, board, checkCheck);
			}
			if ((color == 'r' && x < 2) || (color == 'b' && x < 9)) {
				checkMove(moves, x+1, y-1, piece, color, tempBoard, board, checkCheck);
			}
		}
		if (y < 5) {
			if ((color == 'r' && x > 0) || (color == 'b' && x > 7)) {
				checkMove(moves, x-1, y+1, piece, color, tempBoard, board, checkCheck);
			}
			if ((color == 'r' && x < 2) || (color == 'b' && x < 9)) {
				checkMove(moves, x+1, y+1, piece, color, tempBoard, board, checkCheck);
			}
		}

		return moves;
	}
}
